//
// File  : MainController.cpp
// Team  : Dangling Pointers
// Class : CST 236 - Software Testing
//
// Implementation of the MainController class.
//

#include "BookingController.h"
#include "FlightsController.h"
#include "MainController.h"
#include "CustomerProfileController.h"
#include "FlightStatusController.h"
#include "Global.h"
#include <iostream>


// constructor
MainController::MainController() : m_database(), m_controller(0)
{
	//
	// Populate database with some flights.
	//
	m_database.getFlightDatabase()->addFlight("F100", Flight("F100", "1900", "2030", Flight::ONTIME));
	m_database.getFlightDatabase()->addFlight("F101", Flight("F101", "0000", "0115", Flight::ONTIME));

	//
	// Populate database with some customers.
	//
	m_database.getCustomerDatabase()->addCustomer("Kenley Boss", Customer("Kenley Boss", "989-123-9898", "foo@bar.com"));
	m_database.getCustomerDatabase()->addCustomer("Bhushan Gupta", Customer("Bhushan Gupta", "232-434-4000", "baz@quux.com"));
	m_database.getCustomerDatabase()->addCustomer("Dylan Gleason", Customer("Dylan Gleason", "878-656-1010", "address@domain.com"));
	m_database.getCustomerDatabase()->addCustomer("Josh Hartwell", Customer("Josh Hartwell", "303-111-9490", "hello@world.com"));
	m_database.getCustomerDatabase()->addCustomer("Grant Kropf", Customer("Grant Kropf", "232-913-8785", "software@testing.com"));
	m_database.getCustomerDatabase()->addCustomer("Taehee Ahn", Customer("Taehee Ahn", "503-888-3256", "dangling@pointers.com"));

	displayMenu();
}

// destructor
MainController::~MainController()
{
	delete m_controller;
}

//
// @overrided - displayMenu : void 
//
// Method implements displayMenu function inf Controller interface. MainController will
// prompt user for choice of action (corresponding to each EPIC). Depending on action,
// the corresponding Controller for that action will be instantiated and executed.
//
void MainController::displayMenu()
{
	while(true)
	{
		clearConsole();

		std::cout << std::endl << "======" << "Main Menu" << "======" << std::endl;
		std::cout << "1. Manage Flights." << std::endl;
		std::cout << "2. Book a Flight."  << std::endl;
		std::cout << "3. Check Flight Status." << std::endl;
		std::cout << "4. Customer Profile." << std::endl;
		std::cout << "5. Exit program." << std::endl;

		int input = getUserInput(5);

		//
		// simple factory instantiates controller dynamically based on user choice
		//
		switch(input)
		{
		case 1:
			m_controller = new FlightsController(m_database.getFlightDatabase());
			break;
		case 2:
			m_controller = new BookingController(m_database.getFlightDatabase(), m_database.getCustomerDatabase());
			break;
		case 3:
			m_controller = new FlightStatusController(m_database.getFlightDatabase());
			break;
		case 4:
			m_controller = new CustomerProfileController(m_database.getCustomerDatabase());
			break;
		default:
			return;
		}
	}
}
